package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.mapper.UserInfoMapper;
import com.itheima.service.db.UserInfoService;
import com.itheima.service.db.UserService;
import org.apache.dubbo.config.annotation.Service;

import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;
    //保存用户个人信息
    @Override
    public void save(UserInfo userInfo) {
        //基础的默认假信息数据
        userInfo.setEducation("本科");
        userInfo.setTags("单身,本科,年龄相仿");
        userInfo.setAge(18);
        userInfo.setIncome("30");
        userInfo.setMarriage(0);
        userInfo.setProfession("计算机行业");
        userInfoMapper.insert(userInfo);
    }

    //修改个人头像信息
    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }

    //根据用户的id查询用户对象
    @Override
    public UserInfo findById(Long id) {
        return userInfoMapper.selectById(id);
    }

    //分页查询用户数据
    @Override
    public PageBeanVo findUsers(Integer pageNumber, Integer pageSize) {
        //拼接分页参数
        IPage page = new Page(pageNumber , pageSize);
        //拼接分页条件
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc("id");
        page = userInfoMapper.selectPage(page , queryWrapper);
        return new PageBeanVo(pageNumber , pageSize , page.getTotal() , page.getRecords());
    }
}
